package com.sanjiahantang.youjiaclient.module.category.views.impl;

import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.module.category.beans.CategoryBean;
import com.sanjiahantang.youjiaclient.module.category.presenters.CategoryPresenter;
import com.sanjiahantang.youjiaclient.module.category.views.CategoryView;


/**
 * Created by zy on 2017/9/7.
 */

public class CategoryActivity extends BaseMvpActivity<CategoryView,CategoryPresenter> implements CategoryView, CategoryView.Level1Listener, View.OnClickListener {


    private ListView lvOneLevel;
    private FragmentManager mFragmentManager;
    @Override
    public CategoryPresenter initPresenter() {
        return new CategoryPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.fragment_category);
        presenter.setLevel1Listener(this);
        lvOneLevel = (ListView) findViewById(R.id.lvOneLevel);
        mFragmentManager = getSupportFragmentManager();
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("分类");
        findViewById(R.id.fl_Left).setOnClickListener(this);
    }

    @Override
    public void initData() {
        presenter.onLoad($this);
    }

    @Override
    public void showProgress() {
        super.showProgress($this);
    }


    @Override
    public void initAdapter(QuickAdapter<CategoryBean.Data> level1Adapter) {
        lvOneLevel.setAdapter(level1Adapter);
    }

    @Override
    public void onLevel1Clicked(CategoryBean.Data response) {
        mFragmentManager.beginTransaction().replace(R.id.contents,CategorySubFragment.newInstance(response)).commitAllowingStateLoss();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }
}
